package com.hdit.guimei.service.impl;

import com.hdit.guimei.domain.*;
import com.hdit.guimei.mapper.GoodsMapper;
import com.hdit.guimei.mapper.MycommentMapper;
import com.hdit.guimei.service.MycommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 冰镇小可乐
 * @ClassNameMycommentServiceImpl
 * @Description TODO
 * @Date 2021/1/21 14:06
 * Version 1.0
 */
@Service
public class MycommentServiceImpl implements MycommentService {
    @Autowired
    private MycommentMapper mycommentMapper;
    private GoodsMapper goodsMapper;
    /***
    * @Method 用户添加评论
    * @Author 冰镇小可乐
    * @params  [my_comment]
    * @Return int
    * @Exception
    * @Date 2021/1/21 14:10
    */
    @Override
    public int addMycomment(My_comment my_comment) {
        int i=mycommentMapper.addMycomment(my_comment);
        return i;
    }
    /***
    * @Method 用户查询订单的商品信息 状态自定义
    * @Author 冰镇小可乐
    * @params  [id, order_state]
    * @Return java.util.List<com.hdit.guimei.domain.GoodsComment>
    * @Exception  
    * @Date 2021/1/21 16:11
    */
    @Override
    public List<GoodsOrder> findOrderGood(int id, int order_state) {
        //获取用户已经完成的订单
        List<Order_table> order_tableList=mycommentMapper.findOrderIdByUserId(id,order_state);
        List list =new ArrayList();
        List<GoodsOrder> goodsOrderList =new ArrayList<GoodsOrder>();
        for (Order_table  arg : order_tableList) {
            //查询订单下的商品id
            GoodsOrder goodsOrder =new GoodsOrder();
            Order_item  order_item =  mycommentMapper.findGoodIdByOrderId(arg.getOrder_id());
            Goods goods=goodsMapper.findGoodsByGoods_id(order_item.getGood_id());
            goodsOrder.setGood_id(goods.getGood_id());
            goodsOrder.setGood_name(goods.getGood_name());
            goodsOrder.setPicture_one(goods.getPicture_one());
            goodsOrder.setOrder_id(arg.getOrder_id());
            goodsOrder.setOrder_address(arg.getOrder_address());
            goodsOrder.setOrder_date(arg.getOrder_date());
            goodsOrder.setOrder_state(arg.getOrder_state());
            goodsOrderList.add(goodsOrder);
        }
        return goodsOrderList;
    }
    /***
    * @Method 删除评论
    * @Author 冰镇小可乐
    * @params  [id, good_id]
    * @Return int
    * @Exception  
    * @Date 2021/1/21 16:25
    */
    @Override
    public int deleteMycomment(int id, int good_id) {
        
        int i=mycommentMapper.deleteMycommentByIdAndGoodId(id,good_id);
        return i;
    }
    /***
    * @Method 用户评论
    * @Author 冰镇小可乐
    * @params  [id]
    * @Return java.util.List<com.hdit.guimei.domain.GoodsComment>
    * @Exception  
    * @Date 2021/1/21 16:51
    */
    @Override
    public List<GoodsComment> findGoodsByUser(int id) {
        List<GoodsComment> list =mycommentMapper.findGodosCommentByUser(id);
        return list;
    }
    /***
    * @Method 商品详情页评论
    * @Author 冰镇小可乐
    * @params  [goods_id]
    * @Return java.util.List<com.hdit.guimei.domain.GoodsComment>
    * @Exception  
    * @Date 2021/1/21 16:51
    */
    @Override
    public List<GoodsComment> fingGoodsBy(int good_id) {
        List<GoodsComment> list=mycommentMapper.findGoodsCommentBy(good_id);
        return list;
    }

    @Override
    public List<GoodsComment> findAllGoodsComment() {
        return mycommentMapper.findAllGoodsComment();
    }

    @Override
    public int updateGoodsCommentState(int id, int con_state) {
        Map map = new HashMap();
        map.put("id",id);
        map.put("con_state",con_state);
        return mycommentMapper.updateGoodsCommentState(map);
    }
}
